package com.gmrz.uap.model;

import com.jfinal.render.FileRender;
import java.io.File;

/**
 * @PACKAGE_NAME: com.gmrz.uap.model
 * @ClassName: TempFileRender
 * @Description:  重写 FileRender 类; 用于在文件下载完后，将源文件删除
 * @Date: 2020-07-07 18:34
 * @Author: liyl@gmrz-bj.com
 **/
public class TempFileRender extends FileRender {

    private String fileName;
    private File file;

    public TempFileRender(String fileName) {
        super(fileName);
        this.fileName = fileName;
    }

    public TempFileRender(File file) {
        super(file);
        this.file = file;
    }

    @Override
    public void render() {
        try {
            super.render();
        } finally {

            if(null != fileName) {
                file = new File(fileName);
            }

            if(null != file) {
                // 删除源文件
                file.delete();
                file.deleteOnExit();
            }
        }
    }

}
